package com.kmproject.haifu.mvp.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.http.imageloader.glide.ImageConfigImpl;
import com.jess.arms.utils.ArmsUtils;
import com.jess.arms.utils.DataHelper;
import com.jess.arms.widget.alertview.AlertView;
import com.jess.arms.widget.alertview.AlertViewOnItemClickListener;
import com.jess.arms.widget.autolayout.AutoToolbar;
import com.kmproject.haifu.R;
import com.kmproject.haifu.app.AppConstant;
import com.kmproject.haifu.app.hfinterface.HouseReasonRemovalCallBack;
import com.kmproject.haifu.app.hfinterface.SecondHandItemClickInterface;
import com.kmproject.haifu.app.utils.AppUtil;
import com.kmproject.haifu.di.component.DaggerMyStoreSecondHandComponent;
import com.kmproject.haifu.mvp.contract.MyStoreSecondHandContract;
import com.kmproject.haifu.mvp.model.api.Api;
import com.kmproject.haifu.mvp.model.entity.ResultBean;
import com.kmproject.haifu.mvp.model.entity.beans.HousePayWayBean;
import com.kmproject.haifu.mvp.model.entity.beans.MemberCenterUserInfoBean;
import com.kmproject.haifu.mvp.model.entity.beans.MyStoreMainBean;
import com.kmproject.haifu.mvp.model.entity.beans.MyStoryBean;
import com.kmproject.haifu.mvp.model.entity.beans.PublishNumCheakBean;
import com.kmproject.haifu.mvp.model.entity.beans.SecondHandInfoBean;
import com.kmproject.haifu.mvp.model.entity.resbean.SecondHandQueryParmar;
import com.kmproject.haifu.mvp.presenter.MyStoreSecondHandPresenter;
import com.kmproject.haifu.mvp.ui.adapter.MyStorySecondHandAdapter;
import com.kmproject.haifu.mvp.ui.adapter.SecondHandMainShowAdapter;
import com.kmproject.haifu.mvp.ui.widget.ExpandableTextView;
import com.kmproject.haifu.mvp.ui.widget.RoundCornerImageView;
import com.kmproject.haifu.mvp.ui.widget.ScaleTransitionPagerTitleView;
import com.library.flowlayout.SpaceItemDecoration;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener;

import net.lucode.hackware.magicindicator.MagicIndicator;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.CommonNavigator;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.CommonNavigatorAdapter;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerIndicator;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.indicators.LinePagerIndicator;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.SimplePagerTitleView;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

import static com.jess.arms.utils.Preconditions.checkNotNull;


/**
 * ================================================
 * Description:
 * <p>
 * Created by MVPArmsTemplate on 09/03/2019 09:56
 * <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
 * <a href="https://github.com/JessYanCoding">Follow me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms">Star me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms/wiki">See me</a>
 * <a href="https://github.com/JessYanCoding/MVPArmsTemplate">模版请保持更新</a>
 * ================================================
 */
public class MyStoreSecondHandActivity extends BaseActivity<MyStoreSecondHandPresenter> implements MyStoreSecondHandContract.View {

    @BindView(R.id.toolbar_backImg)
    ImageView toolbarBackImg;
    @BindView(R.id.toolbar_back)
    RelativeLayout toolbarBack;
    @BindView(R.id.toolbar_title)
    TextView toolbarTitle;
    @BindView(R.id.back_right_icon)
    ImageView backRightIcon;
    @BindView(R.id.back_right_txt)
    TextView backRightTxt;
    @BindView(R.id.toolbar_right)
    RelativeLayout toolbarRight;
    @BindView(R.id.toolbar)
    AutoToolbar toolbar;
    @BindView(R.id.mystore_head_headImg)
    RoundCornerImageView mystoreHeadHeadImg;
    @BindView(R.id.mystore_head_name)
    TextView mystoreHeadName;
    @BindView(R.id.mystore_head_dpdj_img)
    TextView mystoreHeadDpdjImg;
    @BindView(R.id.mystore_head_hydj_img)
    ImageView mystoreHeadHydjImg;
    @BindView(R.id.mystore_head_togoUpdate)
    TextView mystoreHeadTogoUpdate;
    @BindView(R.id.mystore_head_fs_txt)
    TextView mystoreHeadFsTxt;
    @BindView(R.id.mystore_head_fs_lay)
    LinearLayout mystoreHeadFsLay;
    @BindView(R.id.mystore_head_pf_txt)
    TextView mystoreHeadPfTxt;
    @BindView(R.id.mystore_head_pf_lay)
    LinearLayout mystoreHeadPfLay;
    @BindView(R.id.mystore_head_lll_txt)
    TextView mystoreHeadLllTxt;
    @BindView(R.id.mystore_head_lll_lay)
    LinearLayout mystoreHeadLllLay;
    @BindView(R.id.mystore_head_dpgl_txt)
    TextView mystoreHeadDpglTxt;
    @BindView(R.id.mystore_head_lll_gz)
    TextView mystoreHeadLllGz;
    @BindView(R.id.mystore_head_gz_lay)
    LinearLayout mystoreHeadGzLay;
    @BindView(R.id.toolbar_layout)
    CollapsingToolbarLayout toolbarLayout;
    @BindView(R.id.mystore_story_indicator)
    MagicIndicator mystoreStoryIndicator;
    @BindView(R.id.app_bar)
    AppBarLayout appBar;
    @BindView(R.id.store_secondHand_RecyclerView)
    RecyclerView storeSecondHandRecyclerView;
    @BindView(R.id.secondHand_refreshLayout)
    SmartRefreshLayout secondHandRefreshLayout;
    @BindView(R.id.secondHand_list_lay)
    LinearLayout secondHandListLay;
    @BindView(R.id.mystore_story_dpmc)
    TextView mystoreStoryDpmc;
    @BindView(R.id.mystore_story_dplx)
    TextView mystoreStoryDplx;
    @BindView(R.id.mystore_story_lxdh)
    TextView mystoreStoryLxdh;
    @BindView(R.id.mystore_story_rzlx)
    TextView mystoreStoryRzlx;
    @BindView(R.id.mystore_story_xxdz)
    TextView mystoreStoryXxdz;
    @BindView(R.id.mystore_story_kdsj)
    TextView mystoreStoryKdsj;
    @BindView(R.id.mystore_story_yyzz_img)
    ImageView mystoreStoryYyzzImg;
    @BindView(R.id.mystore_story_yyzz_lay)
    LinearLayout mystoreStoryYyzzLay;
    @BindView(R.id.mystore_story_jj_ExpandableTextView7)
    ExpandableTextView mystoreStoryJjExpandableTextView7;
    @BindView(R.id.secondHand_dpInfo_lay)
    LinearLayout secondHandDpInfoLay;
    @BindView(R.id.dropdownmenu_layout_RelativeLayout)
    RelativeLayout dropdownmenuLayoutRelativeLayout;
    @BindView(R.id.mystore_secondhand_fbeswp_txt)
    TextView mystoreSecondhandFbeswpTxt;
    @BindView(R.id.mystore_secondhand_dryfb_txt)
    TextView mystoreSecondhandDryfbTxt;
    @BindView(R.id.mystore_secondhand_ckxjsp_txt)
    TextView mystoreSecondhandCkxjspTxt;
    @BindView(R.id.mystore_head_bottom_root_lay)
    LinearLayout mystoreHeadBottomRootLay;
    List<String> titles = new ArrayList<>();
    MyStoreMainBean mmyStoreMainBean;//当前店铺信息
    MyStorySecondHandAdapter myStorySecondHandAdapter;//自己看自己的
    SecondHandQueryParmar secondHandQueryParmar = new SecondHandQueryParmar();
    private SecondHandMainShowAdapter secondHandMainShowAdapter;//别人看我这这个店铺发布得

    PublishNumCheakBean mpublishNumCheakBean;
    private List<HousePayWayBean> mhousePayWayBeansXjTsY;//下架提示语
    MemberCenterUserInfoBean memberCenterUserInfoBean;

    @Override
    public void setupActivityComponent(@NonNull AppComponent appComponent) {
        DaggerMyStoreSecondHandComponent //如找不到该类,请编译一下项目
                .builder()
                .appComponent(appComponent)
                .view(this)
                .build()
                .inject(this);
    }

    @Override
    public int initView(@Nullable Bundle savedInstanceState) {
        return R.layout.activity_my_store_second_hand; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
    }

    @Override
    public String reSetTitle() {
        return getIntent().hasExtra("userId") ? "我的店铺" : "";
    }

    @Override
    public void setTitle(CharSequence title) {
        super.setTitle(getIntent().hasExtra("userId") ? "我的店铺" : "");
    }

    @Override
    protected void onResume() {
        super.onResume();
        mPresenter.getStoreInfo(getIntent().getStringExtra("userStoreId"));
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        if (!getIntent().hasExtra("userStoreId")) {
            showMessage("系统参数异常，请重试");
            killMyself();
            return;
        }
        Drawable drawableLeft = getResources().getDrawable(
                R.drawable.store_swch_icon);
        backRightTxt.setCompoundDrawablesWithIntrinsicBounds(drawableLeft,
                null, null, null);
        backRightTxt.setCompoundDrawablePadding(5);

        memberCenterUserInfoBean = DataHelper.getDeviceData(MyStoreSecondHandActivity.this, AppConstant.user_memberInfo);
        if (memberCenterUserInfoBean.getMemberLevel().getLevelType() == 0) {
            mystoreHeadTogoUpdate.setText("去升级");
        } else {
            mystoreHeadTogoUpdate.setText("去续费");
        }
        getMglideImage().loadImage(this, ImageConfigImpl.builder().url(memberCenterUserInfoBean.getMemberLevel().getHeadImage())
                .imageView(mystoreHeadHydjImg)
                .build());


        if (!getIntent().hasExtra("userId")) {

            backRightTxt.setVisibility(View.INVISIBLE);

            //用户从详情里面跳转过来的，并且不是当前登录用户，只是浏览信息
            mystoreHeadDpglTxt.setVisibility(View.GONE);
            mystoreHeadLllGz.setVisibility(View.VISIBLE);
            mystoreHeadBottomRootLay.setVisibility(View.GONE);
            mystoreHeadTogoUpdate.setVisibility(View.GONE);
            storeSecondHandRecyclerView.setLayoutManager(new GridLayoutManager(this, 2));
            storeSecondHandRecyclerView.addItemDecoration(new SpaceItemDecoration(AppUtil.dp2px(10)));
            secondHandMainShowAdapter = new SecondHandMainShowAdapter(new ArrayList<>());
            storeSecondHandRecyclerView.setAdapter(secondHandMainShowAdapter);
            secondHandMainShowAdapter.openLoadAnimation(BaseQuickAdapter.SCALEIN);
            secondHandRefreshLayout.setEnableRefresh(false);//禁止下拉刷新
            secondHandRefreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {
                @Override
                public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
                    secondHandQueryParmar.setPage(secondHandQueryParmar.getPage() + 1);
                    mPresenter.listSecondHandBycurrentUser(getIntent().getStringExtra("userStoreId"), secondHandQueryParmar);

                }
            });
            mPresenter.listSecondHandBycurrentUser(getIntent().getStringExtra("userStoreId"), secondHandQueryParmar);
        } else {
            toolbarTitle.setTextColor(ArmsUtils.getColor(this, R.color.white));
            toolbar.setBackgroundColor(ArmsUtils.getColor(this, R.color.color_3F3F4B));
            toolbarBackImg.setImageResource(R.drawable.member_center_main_back_img);
            backRightTxt.setTextColor(ArmsUtils.getColor(this, R.color.white));
            backRightTxt.setText(ArmsUtils.getString(this, R.string.mystory_dpqh));
            //可以查看编辑信息
            mystoreHeadTogoUpdate.setVisibility(View.VISIBLE);
            mPresenter.isPublishCount();
            mPresenter.dictList(Api.SECOND_LOWER_SHELF_REASON, "");//下架提示语
            mystoreHeadDpglTxt.setVisibility(View.VISIBLE);
            mystoreHeadLllGz.setVisibility(View.GONE);
            mystoreHeadBottomRootLay.setVisibility(View.VISIBLE);

            storeSecondHandRecyclerView.setLayoutManager(new LinearLayoutManager(this));
//              storeSecondHandRecyclerView.addItemDecoration(new SpaceItemDecoration(AppUtil.dp2px(10)));
            myStorySecondHandAdapter = new MyStorySecondHandAdapter(new ArrayList<>(), new SecondHandItemClickInterface() {
                @Override
                public void callBack(SecondHandInfoBean secondHandInfoBean, HousePayWayBean housePayWayBean, String type) {
                    if (type.equals("Obtained")) {
                        //下架  大大
                        mPresenter.houseReasonRemoval(MyStoreSecondHandActivity.this, mystoreHeadName, mhousePayWayBeansXjTsY, new HouseReasonRemovalCallBack() {
                            @Override
                            public void callBack(HousePayWayBean housePayWayBean) {
                                if (housePayWayBean != null) {
                                    mPresenter.lowerShelfSecondHand( housePayWayBean.getDictId(),secondHandInfoBean.getSecondHandId());
                                }
                            }
                        });
                    } else if (type.equals("del")) {
                        //删除
                        mPresenter.remoredSencond(secondHandInfoBean.getSecondHandId());
                    }
                }
            });
            storeSecondHandRecyclerView.setAdapter(myStorySecondHandAdapter);
            myStorySecondHandAdapter.openLoadAnimation(BaseQuickAdapter.SCALEIN);
            secondHandRefreshLayout.setEnableRefresh(false);//禁止下拉刷新
            secondHandRefreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {
                @Override
                public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
                    secondHandQueryParmar.setPage(secondHandQueryParmar.getPage() + 1);
                    mPresenter.listSecondHandBystore(getIntent().getStringExtra("userStoreId"), secondHandQueryParmar);

                }
            });
            mPresenter.listSecondHandBystore(getIntent().getStringExtra("userStoreId"), secondHandQueryParmar);
            backRightTxt.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    killMyself();
                }
            });
        }
        contralShow(0);
    }

    @Override
    public void showLoading() {
        loadingDialog.show();
    }

    @Override
    public void hideLoading() {
        loadingDialog.dismiss();
    }

    /**
     * 界面显示控制
     *
     * @param index
     */
    public void contralShow(int index) {
        switch (index) {
            case 0:
                //显示列表
                secondHandDpInfoLay.setVisibility(View.GONE);
                secondHandListLay.setVisibility(View.VISIBLE);
                break;
            case 1:
                //显示店铺信息
                secondHandDpInfoLay.setVisibility(View.VISIBLE);
                secondHandListLay.setVisibility(View.GONE);
                break;
        }
    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.snackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @Override
    public void getStoreInfoSuccess(MyStoreMainBean myStoreMainBean) {
        mmyStoreMainBean = myStoreMainBean;

        getMglideImage().loadImage(this, ImageConfigImpl.builder().url(myStoreMainBean.getStoreLogo())
                .imageView(mystoreHeadHeadImg.setmBorderRadius(10))
                .build());
        mystoreHeadName.setText(myStoreMainBean.getStoreName());
        mystoreHeadDpdjImg.setText(myStoreMainBean.getStoreRankName());
        if (!getIntent().hasExtra("userId")) {
            if (myStoreMainBean.getIsAttention() == 0) {
                //未关注
                mystoreHeadLllGz.setText(ArmsUtils.getString(this, R.string.follow_add));
                mystoreHeadLllGz.setTextColor(ArmsUtils.getColor(this, R.color.color_191919));
                mystoreHeadLllGz.setBackgroundResource(R.drawable.button_yellow_bg);
            } else {
                //已关注
                mystoreHeadLllGz.setText(ArmsUtils.getString(this, R.string.is_followed));
                mystoreHeadLllGz.setTextColor(ArmsUtils.getColor(this, R.color.white));
                mystoreHeadLllGz.setBackgroundResource(R.drawable.button_gray_bg);
            }

        }
        mystoreHeadFsTxt.setText(myStoreMainBean.getAttentionCount() + "");
        mystoreHeadPfTxt.setText(myStoreMainBean.getScore() + "");
        mystoreHeadLllTxt.setText(myStoreMainBean.getViewCount() + "");
        titles.clear();

        titles.add("二手物品（" + myStoreMainBean.getSecondHandCount() + "）");
        titles.add("店铺信息");
        CommonNavigator commonNavigator = new CommonNavigator(this);
        commonNavigator.setAdapter(new CommonNavigatorAdapter() {
            @Override
            public int getCount() {
                return titles.size();
            }

            @Override
            public IPagerTitleView getTitleView(Context context, final int index) {

                SimplePagerTitleView simplePagerTitleView = new ScaleTransitionPagerTitleView(context);
                simplePagerTitleView.setText(titles.get(index));
                DisplayMetrics dm = getResources().getDisplayMetrics();
//                simplePagerTitleView.setWidth((dm.widthPixels) / 2);
                simplePagerTitleView.setTextSize(16);
                simplePagerTitleView.setNormalColor(getResources().getColor(R.color.color_191919));
                simplePagerTitleView.setSelectedColor(getResources().getColor(R.color.color_191919));
                LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
//                layoutParams.setMargins(15, 0, 5, 0);//4个参数按顺序分别是左上右下
                simplePagerTitleView.setLayoutParams(layoutParams);
                simplePagerTitleView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mystoreStoryIndicator.onPageSelected(index);
                        commonNavigator.getAdapter().notifyDataSetChanged();
                        contralShow(index);
                    }
                });

                return simplePagerTitleView;
            }

            @Override
            public IPagerIndicator getIndicator(Context context) {
                LinePagerIndicator linePagerIndicator = new LinePagerIndicator(context);
                linePagerIndicator.setMode(LinePagerIndicator.MODE_WRAP_CONTENT);
                linePagerIndicator.setLineHeight(8.0f);
                linePagerIndicator.setColors(ArmsUtils.getColor(MyStoreSecondHandActivity.this, R.color.color_F9D35A));

                return linePagerIndicator;
            }

            @Override
            public float getTitleWeight(Context context, int index) {
                return 1.0f;
            }

        });
        mystoreStoryIndicator.setNavigator(commonNavigator);
        showStoreInfo();
    }

    @Override
    public void listSecondHandSuccess(int curryPage, int totalPage, List<SecondHandInfoBean> secondHandInfoBeans) {
        secondHandRefreshLayout.finishLoadMore();
        if (secondHandInfoBeans == null || secondHandInfoBeans.isEmpty()) {
            secondHandRefreshLayout.setEnableLoadMore(false);
            if (curryPage == 1) {
                myStorySecondHandAdapter.setEmptyView(AppUtil.setEmptyView(MyStoreSecondHandActivity.this, "没有搜索到相关信息", "", null, true));
            }
            return;
        }
        secondHandQueryParmar.setPage(curryPage);
        if (curryPage >= totalPage) {
            secondHandRefreshLayout.setEnableLoadMore(false);
        } else {
            secondHandRefreshLayout.setEnableLoadMore(true);
        }
        if (myStorySecondHandAdapter.getData() == null || myStorySecondHandAdapter.getData().isEmpty()) {
            myStorySecondHandAdapter.setNewData(secondHandInfoBeans);
        } else {
            myStorySecondHandAdapter.addData(secondHandInfoBeans);
        }
    }

    @Override
    public void listSecondHandByUserIdSuccess(int curryPage, int totalPage, List<SecondHandInfoBean> secondHandInfoBeans) {
        secondHandRefreshLayout.finishLoadMore();
        if (secondHandInfoBeans == null || secondHandInfoBeans.isEmpty()) {
            secondHandRefreshLayout.setEnableLoadMore(false);
            if (curryPage == 1) {
                secondHandMainShowAdapter.setEmptyView(AppUtil.setEmptyView(MyStoreSecondHandActivity.this, "没有搜索到相关信息，换个条件试试", "", null, true));
            }
            return;
        }
        secondHandQueryParmar.setPage(curryPage);
        if (curryPage >= totalPage) {
            secondHandRefreshLayout.setEnableLoadMore(false);
        } else {
            secondHandRefreshLayout.setEnableLoadMore(true);
        }
        if (secondHandMainShowAdapter.getData() == null || secondHandMainShowAdapter.getData().isEmpty()) {
            secondHandMainShowAdapter.setNewData(secondHandInfoBeans);
        } else {
            secondHandMainShowAdapter.addData(secondHandInfoBeans);
        }
    }

    @Override
    public void dictListSuccess(List<HousePayWayBean> housePayWayBeans) {
        mhousePayWayBeansXjTsY = housePayWayBeans;
    }

    @Override
    public void lowerShelfSecondHandSuccess() {
        myStorySecondHandAdapter.setNewData(null);
        secondHandQueryParmar.setPage(1);
        mPresenter.listSecondHandBystore(getIntent().getStringExtra("userStoreId"), secondHandQueryParmar);

    }

    @Override
    public void remoredSencondSuccess() {
        myStorySecondHandAdapter.setNewData(null);
        secondHandQueryParmar.setPage(1);
        mPresenter.listSecondHandBystore(getIntent().getStringExtra("userStoreId"), secondHandQueryParmar);

    }

    @Override
    public void userAttentionAddSuccess(ResultBean resultBean) {
        //关注成功
        //已关注
        mmyStoreMainBean.setIsAttention(1);
        mystoreHeadLllGz.setText(ArmsUtils.getString(this, R.string.is_followed));
        mystoreHeadLllGz.setTextColor(ArmsUtils.getColor(this, R.color.white));
        mystoreHeadLllGz.setBackgroundResource(R.drawable.button_gray_bg);
    }

    @Override
    public void userAttentionCancelSuccess(ResultBean resultBean) {
        //未关注
        mmyStoreMainBean.setIsAttention(0);
        mystoreHeadLllGz.setText(ArmsUtils.getString(this, R.string.follow_add));
        mystoreHeadLllGz.setTextColor(ArmsUtils.getColor(this, R.color.color_191919));
        mystoreHeadLllGz.setBackgroundResource(R.drawable.button_yellow_bg);
    }

    @Override
    public void isPublishCountSuccess(PublishNumCheakBean publishNumCheakBean) {
        mpublishNumCheakBean = publishNumCheakBean;
    }

    @OnClick({R.id.mystore_secondhand_ckxjsp_txt, R.id.mystore_secondhand_dryfb_txt, R.id.mystore_secondhand_fbeswp_txt, R.id.mystore_head_lll_gz, R.id.mystore_head_togoUpdate, R.id.mystore_head_dpgl_txt})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.mystore_secondhand_ckxjsp_txt:
                //查看下架
                if (mmyStoreMainBean==null)
                {
                    showMessage("未获取到店铺信息，请重试");
                    mPresenter.getStoreInfo(getIntent().getStringExtra("userStoreId"));
                    return;
                }
                Intent lookObtain=new Intent(this,SecondhandObtainedActivity.class);
                lookObtain.putExtra("MyStoreMainBean",mmyStoreMainBean);
                ArmsUtils.startActivity(lookObtain);
                break;
            case R.id.mystore_secondhand_dryfb_txt:
                //导入
                Intent intentImport=new Intent(this,SecondHandImportToStoreActivity.class);
                intentImport.putExtra("userStoreId",mmyStoreMainBean.getStoreId());
                ArmsUtils.startActivity(intentImport);
                break;
            case R.id.mystore_secondhand_fbeswp_txt:
                //发布二手物品
                if (mpublishNumCheakBean == null) {
                    mPresenter.isPublishCount();
                    showMessage("未获取到配置信息,请重试");
                    return;
                }
                if (mpublishNumCheakBean.getSecondCount() == 0) {
                    new AlertView("", "您的在线二手物品数量已超上限，暂时无法继续发布，您可以升级会员或下架部分二手物品！", "我知道了", new String[]{"去升级会员"}, null, MyStoreSecondHandActivity.this, AlertView.Style.Alert, new AlertViewOnItemClickListener() {

                        @Override
                        public void onItemClick(Object o, int position) {
                            if (position == AlertView.CANCELPOSITION) {

                            } else {
                                Intent intent = new Intent(MyStoreSecondHandActivity.this, MemberCenterMainActivity.class);
                                intent.putExtra("type", "house_updateMember");//从房屋跳转到升级会员界面
                                ArmsUtils.startActivityForResult(intent, 1002);
                            }

                        }
                    }, ArmsUtils.getColor(MyStoreSecondHandActivity.this, R.color.alert_button_00adfcr), true).show();
                    return;
                }
                Intent intent2 = new Intent(MyStoreSecondHandActivity.this, SecondHandPublicshActivity.class);
                ArmsUtils.startActivity(intent2);
                break;
            case R.id.mystore_head_lll_gz:
                if (mmyStoreMainBean == null) {
                    showMessage("未获取到店铺信息");
                    return;
                }
                if (!AppUtil.userIsLogin(this)) {
                    ArmsUtils.startActivity(UserSetingActivity.class);
                    showMessage("请先登录");
                    return;
                }
                if (mmyStoreMainBean.getIsAttention() == 0) {
                    mPresenter.userAttentionAdd(mmyStoreMainBean.getStoreId());
                } else {
                    //取消关注
                    mPresenter.userAttentionCancel(mmyStoreMainBean.getStoreId());
                }

                break;
            case R.id.mystore_head_togoUpdate:
                //去升级
                Intent intent = new Intent(MyStoreSecondHandActivity.this, MemberCenterUpdateLevelActivity.class);
                intent.putExtra("MemberCenterUserInfoBean", memberCenterUserInfoBean);
                startActivity(intent);
                break;
            case R.id.mystore_head_dpgl_txt:
                Intent intent3 = new Intent(MyStoreSecondHandActivity.this, MyStoryAddStoryActivity.class);
                intent3.putExtra("MyStoreMainBean", mmyStoreMainBean);
                startActivityForResult(intent3, 1002);
                break;

        }
    }

    /**
     * 显示店铺信息
     */
    public void showStoreInfo() {

        mystoreStoryDpmc.setText(mmyStoreMainBean.getStoreName());
        mystoreStoryDplx.setText(mmyStoreMainBean.getStoreTypeName());
        mystoreStoryLxdh.setText(AppUtil.mobil(mmyStoreMainBean.getStoreMobile()));
        String temShow = "";
        if ((mmyStoreMainBean.getPassport() != null && !TextUtils.isEmpty(mmyStoreMainBean.getPassport())) || ((mmyStoreMainBean.getIdCardFront() != null && !TextUtils.isEmpty(mmyStoreMainBean.getIdCardFront()) && mmyStoreMainBean.getIdCardReverseSide() != null && !TextUtils.isEmpty(mmyStoreMainBean.getIdCardReverseSide())))) {
            temShow = "身份认证";
        }
        if (mmyStoreMainBean.getBusinessLicense() != null && !TextUtils.isEmpty(mmyStoreMainBean.getBusinessLicense())) {
            if (TextUtils.isEmpty(temShow)) {
                temShow = "营业执照";
            } else {
                temShow += "、营业执照";
            }
        }
        if (TextUtils.isEmpty(temShow)) {
            temShow = "无";
        }
        mystoreStoryRzlx.setText(temShow);
        mystoreStoryXxdz.setText(mmyStoreMainBean.getAddressDetail());
        mystoreStoryKdsj.setText(mmyStoreMainBean.getCreateTime().substring(0, 10));
        mystoreStoryJjExpandableTextView7.setOriginalText(mmyStoreMainBean.getStoreDetail());
        if (mmyStoreMainBean.getBusinessLicense() == null || TextUtils.isEmpty(mmyStoreMainBean.getBusinessLicense())) {
            mystoreStoryYyzzLay.setVisibility(View.GONE);
            return;
        }
        getMglideImage().loadImage(this, ImageConfigImpl.builder().url(mmyStoreMainBean.getBusinessLicense())
                .imageView(mystoreStoryYyzzImg)
                .build());
        mystoreStoryYyzzImg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                List<String> temPaths = new ArrayList<>();
                temPaths.add(mmyStoreMainBean.getBusinessLicense());
                AppUtil.lookBigImg(MyStoreSecondHandActivity.this, mmyStoreMainBean.getBusinessLicense(), temPaths);
            }
        });
    }
}
